/**
 * Copyright (C), 2015-2019, bogewang有限公司
 * FileName: UserMapper
 * Author:   bogewang
 * Date:     2019/9/7 17:41
 * Description: 用户mapper
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.bogewang.member.mapper;

import com.bogewang.member.entity.UserDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.repository.query.Param;

/**
 * 〈用户mapper〉
 *
 * @author bogewang
 * @create 2019/9/7
 * @since 1.0.0
 */
public interface UserMapper {

    @Insert("INSERT INTO `meite_user` VALUES (null,#{mobile}, #{email}, #{password}, #{userName}, null, null, null, '1', null, null, null);")
    int register(UserDTO userDTO) ;

    @Select("SELECT t.username, t.mobile FROM meite_user t WHERE MOBILE=#{mobile};")
    UserDTO existMobile(@Param("mobile") String mobile) ;

    @Select(" SELECT USERID, MOBILE, EMAIL, PASSWORD, USERNAME ,SEX, AGE, CREATETIME, ISAVAILABLE, PICIMG," +
            " QQOPENID,WXOPENID FROM meite_user  WHERE MOBILE=#{0} and password=#{1};")
    UserDTO login(@Param("mobile") String mobile, @Param("password") String password);

    @Select("SELECT USERID ,MOBILE,EMAIL,PASSWORD, USERNAME ,SEX ,AGE , CREATETIME,ISAVAILABLE ,PICIMG, " +
            "QQOPENID,WXOPENID FROM meite_user WHERE USERID=#{userId}")
    UserDTO findByUserId(@Param("userId") Long userId);

    @Select("SELECT USERID ,MOBILE, EMAIL, PASSWORD,  USERNAME , SEX , AGE , CREATETIME, ISAVAILABLE, PICIMG, QQOPENID, WXOPENID"
            + " FROM meite_user WHERE qqopenid=#{qqOpenId}")
    UserDTO findByOpenId(@Param("qqOpenId") String qqOpenId);

    @Update("update meite_user set QQOPENID =#{0} WHERE USER_ID=#{1}")
    int updateUserOpenId(@Param("qqOpenId") String qqOpenId, @Param("userId") Long userId);

}